package org.jsbd.boss.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.dao.IInviteCodeConfigDao;
import org.jsbd.boss.domian.Role;
import org.jsbd.boss.domian.channel.InviteConfig;
import org.jsbd.boss.domian.channel.InviteConfigProbability;
import org.springframework.stereotype.Repository;

import edu.hziee.common.dbroute.BaseDAO;

@Repository("inviteCodeConfigDao")
public class InviteCodeConfigDaoImpl extends BaseDAO implements IInviteCodeConfigDao {

	@Override
	public Map<String, Object> getConfigList(DataGridModel page, InviteConfig inviteConfig) {
		inviteConfig = (inviteConfig == null ? new InviteConfig() : inviteConfig);
		inviteConfig.setPageInfo(page);
	    Map<String, Object> results = new HashMap<String, Object>();
	    results.put("total", super.queryForCount("qy_channel_invite_code_config.SELECT_CONFIG_COUNT", inviteConfig));
	    results.put("rows", super.queryForList("qy_channel_invite_code_config.SELECT_CONFIG_LIST", inviteConfig));
	    return results;
	}

	@Override
	public void save(InviteConfig inviteConfig) {
		super.insert("qy_channel_invite_code_config.INSERT_INVITE_CONFIG", inviteConfig);
	}

	@Override
	public InviteConfig getById(Integer id) {
		return (InviteConfig) super.queryForObject("qy_channel_invite_code_config.SELECT_BY_ID", id);
	}

	@Override
	public void update(InviteConfig inviteConfig) {
		super.update("qy_channel_invite_code_config.UPDATE_INVITE_CONFIG", inviteConfig);
	}

	@Override
	public void delete(Integer id) {
		super.update("qy_channel_invite_code_config.DELETE_INVITE_CONFIG", id);
	}

	@Override
	public InviteConfig getByMark(String mark) {
		return (InviteConfig) super.queryForObject("qy_channel_invite_code_config.SELECT_BY_MARK", mark);
	}

	@Override
	public void insertInviteCodeProbability(List<InviteConfigProbability> list) {
		super.batchInsert("qy_channel_invite_code_config.INSERT_INVITE_CODE_PROBABILITY", list);
	}

	@Override
	public List<InviteConfigProbability> selectInviteCodeProbability(Integer id) {
		return super.queryForList("qy_channel_invite_code_config.SELECT_INVITE_CODE_PROBABILITY", id);
	}

	@Override
	public void deleteInviteCodeProbability(Integer id) {
		super.delete("qy_channel_invite_code_config.DELETE_INVITE_CODE_PROBABILITY", id);
	}

	@Override
	public void updateTotalCountAvg(Integer inviteId, Float totalCountAvg) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("inviteId", inviteId);
		map.put("totalCountAvg", totalCountAvg);
		super.update("qy_channel_invite_code_config.UPDATE_TOTAL_COUNT_AVG", map);
	}

}
